﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WTSQCB
{
    public partial class ThongKeTheoLop : System.Web.UI.Page
    {
        private string chuoiketnoi = ConfigurationManager.ConnectionStrings["WebDiemTSQCBConnectionString"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        SqlDataAdapter da;
        DataSet ds = new DataSet();
        SqlCommand cmd = new SqlCommand();
        SqlConnection con;

        public void BindData()
        {
            con = new SqlConnection(chuoiketnoi);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "XemLop";
            cmd.Parameters.AddWithValue("@malop", tbMalop.Text);
            cmd.Connection = con;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            con.Open();
            cmd.ExecuteNonQuery();
            grdThongKe.DataSource = SqlDataSource1;
            SqlDataSource1.Update();
            grdThongKe.DataBind();
            con.Close();
        }
        protected void btnXem_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "XemLop";
                cmd.Parameters.AddWithValue("@malop", tbMalop.Text);             
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();           
                grdThongKe.DataBind();
                Response.Write("Load thành công");
          
            }
            catch (Exception ex)
            {
                Response.Write("không thực hiện được");
            }
        }









        public void LoadGirdView()
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                con.Open();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "XemLop";
                //cmd.ExecuteNonQuery();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                grdThongKe.DataSource = ds;
                grdThongKe.DataBind();
                Response.Write("Load thành công");
                con.Close();
            }
            catch
            {
                Response.Write("không thực hiện được");
            }
        }


        protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}